package com.ruoyi.basicdata.service.impl;

import java.util.List;

import com.ruoyi.basicdata.domain.Village;
import com.ruoyi.basicdata.mapper.BuildingMapper;
import com.ruoyi.basicdata.mapper.ResidentMapper;
import com.ruoyi.basicdata.mapper.VillageMapper;
import com.ruoyi.basicdata.service.IVillageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 基础资料Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-04-05
 */
@Service
public class VillageServiceImpl implements IVillageService
{
    @Autowired
    private VillageMapper villageMapper;
    @Autowired
    private BuildingMapper buildingMapper;
    @Autowired
    private ResidentMapper residentMapper;


    /**
     * 查询基础资料
     * 
     * @param id 基础资料主键
     * @return 基础资料
     */
    @Override
    public Village selectVillageById(Long id)
    {
        return villageMapper.selectVillageById(id);
    }

    /**
     * 查询基础资料列表
     * 
     * @param village 基础资料
     * @return 基础资料
     */
    @Override
    public List<Village> selectVillageList(Village village)
    {
        return villageMapper.selectVillageList(village);
    }

    /**
     * 新增基础资料
     * 
     * @param village 基础资料
     * @return 结果
     */
    @Override
    public int insertVillage(Village village)
    {
        return villageMapper.insertVillage(village);
    }

    /**
     * 修改基础资料
     * 
     * @param village 基础资料
     * @return 结果
     */
    @Override
    public int updateVillage(Village village)
    {
        return villageMapper.updateVillage(village);
    }

    /**
     * 批量删除基础资料
     * 
     * @param ids 需要删除的基础资料主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteVillageByIds(Long[] ids){
        buildingMapper.deleteBuildingByVillageIds(ids);
        residentMapper.deleteResidentByVillageIds(ids);
        return villageMapper.deleteVillageByIds(ids);
    }

    /**
     * 删除基础资料信息
     * 
     * @param id 基础资料主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteVillageById(Long id){
        buildingMapper.deleteBuildingByVillageId(id);
        residentMapper.deleteResidentByVillageId(id);
        return villageMapper.deleteVillageById(id);
    }

    @Override
    public List<Village> selectVillages() {
        return villageMapper.selectVillages();
    }
}
